﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class CourseSystem : System.Web.UI.PageEx
{
    private DataSet ds = null;
    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strSelectId = string.Empty;
    private string strBigSelectId = string.Empty;
    private string strSmallSelectId = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        strSelectId = Convert.ToString(Request.QueryString["ClassId"]);
        string strTempSelectId = strSelectId.StartsWith("|0|") ? strSelectId.Substring(2) : strSelectId;
        strTempSelectId = strTempSelectId.Trim('|');
        string[] arrSelectId = strTempSelectId.Split('|');
        strBigSelectId = arrSelectId[0];
        strSmallSelectId = arrSelectId.Length > 0 ? arrSelectId[arrSelectId.Length - 1] : arrSelectId[0];

        if (!Page.IsPostBack)
        {
            DataBinds();
        }
    }

    private void DataBinds()
    {
        int iSelectId = 0;
        int.TryParse(strSmallSelectId, out iSelectId);
        Model.DbClass dbClass = DalEx.DbClassEx.Select(iSelectId);
        if (dbClass != null)
            ltShowSubject0.Text = ltShowSubject1.Text = dbClass.CName;
        //绑定左侧类别菜单
        ds = DalEx.DbClassEx.Select(" and cStatus=1 and cType=2 and cLevel=0 order by cOrder asc,cId desc");
        rptClassMenu.DataSource = ds;
        rptClassMenu.DataBind();
        //绑定课程列表数据
        string strQuery = " and aLang='Course'";
        if (!string.IsNullOrEmpty(strSelectId))
            ////////////////////////大类显示大类,小类显示小类
            //strQuery += " and aClassIds like '%|" + iSelectId + "%|'";
            strQuery += " and aClassId = '" + iSelectId + "'";
        ds = WebBase.Comm.SelectByPage("dbArticles ", "*", "aId", strQuery + " and aStatus=1", anpProduct.PageSize, anpProduct.CurrentPageIndex, "aOrder", 0, out iPageCount, out iRecordCount);
        anpProduct.RecordCount = iRecordCount;
        rptDataList.DataSource = ds;
        rptDataList.DataBind();
    }
    protected void anpProduct_PageChanged(object sender, EventArgs e)
    {
        DataBinds();
    }
    protected void rptClassMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            Repeater rptSubClassMenu = (Repeater)e.Item.FindControl("rptSubClassMenu");
            DataRowView drv = (DataRowView)e.Item.DataItem;
            ds = DalEx.DbClassEx.Select(" and cStatus=1 and cType=2 and cUpId=" + Convert.ToInt32(drv["cId"]) + " order by cOrder asc,cId desc");
            rptSubClassMenu.DataSource = ds;
            rptSubClassMenu.DataBind();

            HtmlGenericControl dtClass = (HtmlGenericControl)e.Item.FindControl("dtClass");
            HtmlGenericControl ddClass = (HtmlGenericControl)e.Item.FindControl("ddClass");
            if (Convert.ToString(drv["cId"]) == strBigSelectId)
            {
                dtClass.Attributes.Add("class", "current");
                ddClass.Attributes.Add("style", "display: block;");
            }
            else
            {
                dtClass.Attributes.Add("class", "");
                ddClass.Attributes.Add("style", "display: none;");
            }
        }
    }
}
